﻿using ChronoScript_Compiler.Language;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Viper.Opcodes;

namespace ChronoScript_Compiler.CodeGen
{
    public partial class CodeGen
    {
        private static uint ifIndex = 0;
        public void ParseIf(LanguageDefinition.IfStatement ifstat)
        {
            ParseBooleanExpression(ifstat.Comparison);
            string label = "if_" + ifIndex.ToString();
            string label2 = "else_" + ifIndex.ToString();
            ifIndex++;
            Assembler.Emit(new bz(label));
            CompileBlock(ifstat.Body);
            Assembler.Emit(new bra(label2));
            Assembler.CreateGlobalLabel(label);
            CompileBlock(ifstat.Else);
            Assembler.CreateGlobalLabel(label2);

        }
    }
}
